package Test;


import java.util.Scanner;

public class Fibonacci {
    public void getFibonacci(){
        System.out.print("请输入斐波那契数列长度：");
        Scanner in=new Scanner(System.in);
        int length=in.nextInt();
        Fibonacci.generateFibonacci(length);

    }

    public static void generateFibonacci(int length){
        int fn2=0;
        int fn1=1;

        System.out.print(fn2+" "+fn1);
        for(int i=3;i<=length;i++){
            System.out.print(" ");
            System.out.print(fn2+fn1);
            int temp=fn2;
            fn2=fn1;
            fn1=temp+fn1;

        }

    }


    public static void main(String[] args){
        Fibonacci fibonacci=new Fibonacci();
        fibonacci.getFibonacci();

    }
}
